<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="甘忠祥">
    <title>输入字数统计</title>
    <style>
        .container{
            width: 500px;
            margin: 20px auto;
        }
        .container div{
            margin-left: 240px;
            font-size: 20px;
        }
        i{
            font-weight: bold;
        }
    </style>
</head>

<body>
    <div class="container">
        <div>已输入<i>00</i>字</div>
        <form>
            <textarea rows="8" cols="40" oninput="onInput()"></textarea>
        </form>
    </div>
</body>
<script src="./jquery.min.js"></script>
<script>
    // str.charCodeAt(0) > 255 是中文
	// length 中文：+1  英文：+0.5
        var count = 0;
        function onInput(){
              for( i = 0; i < $('textarea').val().length; i++){
                if($('textarea').val().charCodeAt(i) > 255){
                    count = count + 1;
                } else {
                    count = count + 0.5;
                }
              }
              $('i').html(Math.ceil(count));
              if (count > 100) {
                  $('i').css('color','red')
              }
                  
              count = 0;
        };


</script>
</html>